package com.lanlian.cayman.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.lanlian.cayman.R;
import com.lanlian.cayman.activity.WebviewActivity;
import com.lanlian.commonlib.bean.BannerInfo;
import com.lanlian.commonlib.common.SystemConfig;
import com.lanlian.imagelib.ShowImageUtils;
import com.lanlian.uikit.banner.RecyclingPagerAdapter;
import com.lanlian.utillib.ViewFindUtils;

import java.util.ArrayList;

/**
 * <pre>
 *     author : huxiaobo
 *     e-mail : huxiaobo@xlanlian.com
 *     date   : 2018/8/31 15:07
 *     desc   : todo
 *     version: 1.0
 * </pre>
 */
public class InformationBannerAdapter extends RecyclingPagerAdapter {

    private Context mContext;
    private ArrayList<BannerInfo> mList;

    public InformationBannerAdapter(Context mContext, ArrayList<BannerInfo> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup container) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_information_banner, null);
        }
        ImageView mImgBanner = ViewFindUtils.find(convertView, R.id.img_banner);
        ShowImageUtils.showImageViewFitCenter(mContext, mList.get(position % mList.size()).getImageURL(),
                SystemConfig.IMG_DEFAULT_BACKGROUND, mImgBanner);
        mImgBanner.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!TextUtils.isEmpty(mList.get(position % mList.size()).getNewsURL())) {
                    mContext.startActivity(new Intent(mContext, WebviewActivity.class)
                            .putExtra("url", mList.get(position % mList.size()).getNewsURL())
                            .putExtra("title", "资讯详情"));
                }
            }
        });
        return convertView;
    }

    @Override
    public int getCount() {
        return mList.size() * 100;
    }

}
